﻿@model IEnumerable<LeadMaster.Models.PurchaseOrders>

@{
    ViewBag.Title = "Index";
}

<style type="text/css">
td
{
    font-size: 11px;
    font-family: Arial;
}
</style>

<div class="spacer"></div>
<h2>Purchase Orders @if(ViewBag.Title==null){@ViewBag.Title}</h2>
<div class="spacer"></div>
@using (Html.BeginForm())
{
<label>Internal Ref</label>
<input type="text" name="intRef" />
<input type="submit" value="Filter On This" />
}
<div class="spacer"></div>
<table class="listtable contactstable" style="width: 100%;" cellspacing="0" cellpadding="0">
    <tr>
        <th>
@Html.LabelFor(model => model.FirstOrDefault().Lead.Company.Company)
        </th>
        <th>
            @Html.LabelFor(model => model.FirstOrDefault().WeekNo)
        </th>
        <th>
            @Html.LabelFor(model => model.FirstOrDefault().WeekBeginning)
        </th>
        <th>
            @Html.LabelFor(model => model.FirstOrDefault().WeekEnding)
        </th>
        <th>
            @Html.LabelFor(model => model.FirstOrDefault().Quantity)
        </th>
        <th>
            @Html.LabelFor(model => model.FirstOrDefault().PID)
        </th>
        <th>
            @Html.LabelFor(model => model.FirstOrDefault().Accepted)
        </th>
        <th>
            @Html.LabelFor(model => model.FirstOrDefault().Rejected)
        </th>
        <th>
            @Html.LabelFor(model => model.FirstOrDefault().Replaced)
        </th>
        <th>
            @Html.LabelFor(model => model.FirstOrDefault().InvalidReturns)
        </th>
        <th>
            @Html.LabelFor(model => model.FirstOrDefault().Deficit)
        </th>
        <th>
            @Html.LabelFor(model => model.FirstOrDefault().TotalLeadsSupplied)
        </th>
        <th>
            @Html.LabelFor(model => model.FirstOrDefault().CallCentre)
        </th>
        <th>
            @Html.LabelFor(model => model.FirstOrDefault().ClientPaid)
        </th>
        <th>
            @Html.LabelFor(model => model.FirstOrDefault().Visible)
        </th>
        <th>
            @Html.LabelFor(model => model.FirstOrDefault().SalesInvoiceNumber)
        </th>

        <th style="width: 200px;"></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td @if (item.terminated==true)
	{
		 @:style="color: #800000""
	}>
            @Html.DisplayFor(modelItem => item.Lead.IntRef) @Html.DisplayFor(modelItem => item.Lead.Company.Company)
        </td>
        <td @if (item.terminated==true)
	{
		 @:style="color: #800000""
	}>
            @Html.DisplayFor(modelItem => item.WeekNo)
        </td>
        <td @if (item.terminated==true)
	{
		 @:style="color: #800000""
	}>
            @Html.DisplayFor(modelItem => item.WeekBeginning)
        </td>
        <td @if (item.terminated==true)
	{
		 @:style="color: #800000""
	}>
            @Html.DisplayFor(modelItem => item.WeekEnding)
        </td>
        <td @if (item.terminated==true)
	{
		 @:style="color: #800000""
	}>
            @Html.DisplayFor(modelItem => item.Quantity)
        </td>
        <td @if (item.terminated==true)
	{
		 @:style="color: #800000""
	}>
            @Html.DisplayFor(modelItem => item.PID)
        </td>
        <td @if (item.terminated==true)
	{
		 @:style="color: #800000""
	}>
            @Html.DisplayFor(modelItem => item.Accepted)
        </td>
        <td @if (item.terminated==true)
	{
		 @:style="color: #800000""
	}>
            @Html.DisplayFor(modelItem => item.Rejected)
        </td>
        <td @if (item.terminated==true)
	{
		 @:style="color: #800000""
	}>
            @Html.DisplayFor(modelItem => item.Replaced)
        </td>
        <td @if (item.terminated==true)
	{
		 @:style="color: #800000""
	}>
            @Html.DisplayFor(modelItem => item.InvalidReturns)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Deficit)
        </td>
        <td @if (item.terminated==true)
	{
		 @:style="color: #800000""
	}>
            @Html.DisplayFor(modelItem => item.TotalLeadsSupplied)
        </td>
        <td @if (item.terminated==true)
	{
		 @:style="color: #800000""
	}>
            @Html.DisplayFor(modelItem => item.CallCentre.CallCentre)
        </td>
        <td>
        @if (item.ClientPaid==true)
        {
            <img src="../../Images/tick.png" />
        }
        </td>
        <td>
        @if (item.Visible==true)
        {
            <img src="../../Images/tick.png" />
        }
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.SalesInvoiceNumber)
        </td>

        <td>
            @Html.ActionLink("Edit", "Edit", new { id = item.PurchaseOrderID }) |
            <!--@Html.ActionLink("Details", "Details", new { id = item.PurchaseOrderID }) |-->
            @Html.ActionLink("Delete", "Delete", new { id = item.PurchaseOrderID })
            @if (item.terminated!=true)
            {
            <label style="color: rgb(35, 111, 169); font-weight: normal; cursor: pointer;" class="terminatelead" data-id="@(item.PID)"> | Terminate</label>
            }
            | @Html.ActionLink("Tracker", "OutsourcerTracker", new { callCentreID = @item.CallCentreID })
        </td>
    </tr>
}

</table>

<div id="dialog-confirm" title="Terminate this Order?">
  <p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>This will terminate this order - no more leads will be submitted against it. Are you sure?</p>
</div>

<input type="hidden" id="hdnpid" value="" />

<script type="text/javascript">
    $(document).ready(function () {

        $('.terminatelead').click(function () {
            $("#hdnpid").val($(this).data("id"));
            $("#dialog-confirm").dialog("open");
        });

        $(function () {
            $("#dialog-confirm").dialog({
                autoOpen: false,
                resizable: false,
                height: 200,
                modal: true,
                buttons: {
                    "Terminate": function () {
                        $.ajax({
                            type: "GET",
                            url: '@(Url.Action("Terminate", "PurchaseOrder"))/?pid=' + $("#hdnpid").val()
                        });
                        $(this).dialog("close");
                    },
                    Cancel: function () {
                        $(this).dialog("close");
                    }
                }
            });
        });

    });
</script>
